/*
 * Copyright (c) 2012 swing-on-fire Team
 * 
 * This file is part of Swing-On-Fire (http://code.google.com/p/swing-on-fire), licensed under the terms of the MIT
 * License (MIT).
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
 * Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package com.google.code.swingonfire.component.page.old;

import java.awt.Component;

import com.google.code.swingonfire.utility.interpolation.Interpolations;

public class JPageTransitionAnimationFactory extends AbstractJPageAnimationFactory
{

    public static JPageTransitionAnimationFactory fadeIn(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().fadeIn(),
            new JPageTransition().fadeOut());
    }

    public static JPageTransitionAnimationFactory fadeInAndShrink(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().fadeIn().scaleToFit(1.5),
            new JPageTransition().fadeOut());
    }

    public static JPageTransitionAnimationFactory fadeInFromLeft(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().fadeIn().moveInFromLeft(0.33),
            new JPageTransition().fadeOut());
    }

    public static JPageTransitionAnimationFactory fadeInFromRight(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().fadeIn().moveInFromRight(0.33),
            new JPageTransition().fadeOut());
    }

    public static JPageTransitionAnimationFactory fadeInFromTop(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().fadeIn().moveInFromTop(0.33),
            new JPageTransition().fadeOut());
    }

    public static JPageTransitionAnimationFactory fadeInFromBottom(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().fadeIn().moveInFromBottom(0.33),
            new JPageTransition().fadeOut());
    }

    public static JPageTransitionAnimationFactory fadeInFromLeftAndShrink(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().fadeIn().moveInFromLeft(0.5)
            .scaleToFit(2), new JPageTransition().fadeOut());
    }

    public static JPageTransitionAnimationFactory fadeInFromRightAndShrink(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().fadeIn().moveInFromRight(0.5)
            .scaleToFit(2), new JPageTransition().fadeOut());
    }

    public static JPageTransitionAnimationFactory fadeInFromTopAndShrink(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().fadeIn().moveInFromTop(0.5)
            .scaleToFit(2), new JPageTransition().fadeOut());
    }

    public static JPageTransitionAnimationFactory fadeInFromBottomAndShrink(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().fadeIn().moveInFromBottom(0.5)
            .scaleToFit(2), new JPageTransition().fadeOut());
    }

    public static JPageTransitionAnimationFactory sequentialFade(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().fadeIn(Interpolations.sequential()
            .add(Interpolations.fix(0)).add(0.375, Interpolations.soft())),
            new JPageTransition().fadeOut(Interpolations.sequential().add(Interpolations.soft())
                .add(0.625, Interpolations.fix(1))));
    }

    public static JPageTransitionAnimationFactory moveInFromRight(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().moveInFromRight(1.1),
            new JPageTransition().moveOutToLeft(1.1));
    }

    public static JPageTransitionAnimationFactory moveInFromLeft(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().moveInFromLeft(1.1),
            new JPageTransition().moveOutToRight(1.1));
    }

    public static JPageTransitionAnimationFactory moveInFromTop(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().moveInFromTop(1.1),
            new JPageTransition().moveOutToBottom(1.1));
    }

    public static JPageTransitionAnimationFactory moveInFromBottom(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition().moveInFromBottom(1.1),
            new JPageTransition().moveOutToTop(1.1));
    }

    public static JPageTransitionAnimationFactory newspaperFromRight(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition()
            .rotate(Interpolations.linear(), duration * 5).scaleToFit(Interpolations.accelerating(), 0)
            .moveIn(Interpolations.accelerating(), 0.4, -0.3), new JPageTransition().fadeOut());
    }

    public static JPageTransitionAnimationFactory newspaperFromLeft(double duration)
    {
        return new JPageTransitionAnimationFactory(duration, new JPageTransition()
            .rotate(Interpolations.linear(), duration * 5).scaleToFit(Interpolations.accelerating(), 0)
            .moveIn(Interpolations.accelerating(), -0.4, 0.3), new JPageTransition().fadeOut());
    }

    private final JPageTransition nextTransition;
    private final JPageTransition previousTransition;

    public JPageTransitionAnimationFactory(double duration, JPageTransition nextTransition,
        JPageTransition previousTransition)
    {
        super(duration);

        this.nextTransition = nextTransition;
        this.previousTransition = previousTransition;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public JPageAnimation createAnimation(Component pageComponent, Component nextComponent, Component previousComponent)
    {
        return new JPageTransitionAnimation(getDuration(), nextTransition, previousTransition, pageComponent,
            nextComponent, previousComponent);
    }

}
